const http = require("http");
const fs = require("fs");

http
  .createServer(function (request, response) {
    console.log("request come", request.url);
    if (request.url === "/") {
      response.writeHead(302, {
        // 301 是永久重定向，使用时要慎重，301缓存在浏览器中没有时间限制，除非用户自己清缓存
        // 302 是临时重定向
        Location: "/new",
      });
      response.end("");
    }
    if (request.url === "/new") {
      response.writeHead(200, {
        "Content-Type": "text/html",
      });
      response.end("<div>this is content</div>");
    }
  })
  .listen(8888);

console.log("server listening on 8888");
